home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / Snippets / Toolbox / DateThing / DateDialog.c next >
Encoding:
C/C++ Source or Header  |  1993-08-05  |  22.5 KB  |  615 lines  |  [TEXT/MPS ]

  1. /* DateDialog.c */
  2. /* an example of how to create a date-adjuster type thing */
  3. /* as used in the General control panel */
  4.  
  5. /* C.K. Haun <TR> */
  6. #include "DateThing.h"
  7. /* protos for this file */
  8.  
  9. static ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem);
  10. static void WritePicturedNum(long theNum, short width);
  11. static pascal void BorderDefault(DialogPtr dwind, short dinum);
  12. static void DrawIndString(short strList, short index);
  13. static pascal void DateBox(WindowPtr rDial, short dinum);
  14. static void AdjustDate(short incOr, DialogPtr rDial, short newVal);
  15. static pascal Boolean DateThingerFilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit);
  16.  
  17. /* exported */
  18. void DateSetterDialog(void);
  19.  
  20. /* I like to keep the seconds and the 'real' representation of the date all the */
  21. /* time instead of doing a lot of conversions */
  22. /* so this struct */
  23.  
  24. typedef struct DateStruct {
  25.     Boolean inUse;
  26.     unsigned long startDateraw;
  27.     unsigned long endDateraw;
  28.     DateTimeRec startDate;
  29.     DateTimeRec endDate;
  30. } DateStruct, *DatePtr, **DateHdl;
  31.  
  32. typedef struct dateBoxStruct {
  33.     DateStruct dialogDate;  /* contains the current start and end dates */
  34.     Rect charBox[6];        /* rectangles containing the numbers */
  35.     Rect arrowHits[2];      /* test if the user is in my arrows */
  36.     Boolean editHot;        /* if this is active. aways true in this example */
  37.                             /* this is in here if you also have an edit line in the dialog */
  38.                             /* and you need to direct keys to that edit line instead of the */
  39.                             /* date thing sometimes */
  40.     short whichHitting;     /* what month/day etc. are we currently in? */
  41.     Rect thing;             /* where the thing goes */
  42.     long lastLetterTick;    /* when was the last time they typed something */
  43.     short lastWhichHit;     /* in what area? */
  44. } dateBoxStruct;
  45. static dateBoxStruct dialogDateStruct;
  46.  
  47. enum  {
  48.     kManDateItem = 3, kBorderBox
  49. };
  50.  
  51. enum  {
  52.     kStartMonth = 0, kStartDay, kStartYear, kEndMonth, kEndDay, kEndYear
  53. };
  54. #pragma segment Main
  55.  
  56. /* Gets the ControlHandle for the item you want in the dialog box thebox. */
  57. /* Handy for setting checkboxes and radio buttons */
  58.  
  59. static ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
  60. {
  61.     short itemtype;
  62.     Rect itemrect;
  63.     Handle thandle;
  64.     
  65.     GetDItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
  66.     return((ControlHandle)thandle);
  67. }
  68.  
  69. /* end SnatchHandle */
  70.  
  71. /* puts leading spaces as needed */
  72. /* replaces <# # # # #> in FORTH */
  73.  
  74. static void WritePicturedNum(long theNum, short width)
  75. {
  76.     Str32 theNumber;
  77.     short spAdd = 0;
  78.     NumToString(theNum, &theNumber);
  79.     if (width <= 31) {
  80.         if (theNumber[0] != width) {
  81.             /* padd until */
  82.             /* shift over some */
  83.             spAdd = width - theNumber[0];
  84.             BlockMove((Ptr)&theNumber[1], (Ptr)&theNumber[spAdd + 1], theNumber[0]);
  85.             
  86.             while (spAdd) {
  87.                 theNumber[spAdd] = '0';
  88.                 spAdd--;
  89.             }
  90.             theNumber[0] = width;
  91.         }
  92.     }
  93.     DrawString(theNumber);
  94.     
  95. } /* end WritePicturedNum */
  96.  
  97. /* util */
  98.  
  99. /* BorderDefault draws a heavy border around the default button (in this case the OK button ) */
  100. /* Not necessary if SetDefaultItem is used in System 7 (see DialogBits 2.0.1) */
  101.  
  102. static pascal void BorderDefault(DialogPtr dwind, short dinum)
  103. {
  104. #pragma unused (dinum)
  105.     short itemtype;
  106.     Handle itemhandle;
  107.     Rect borderRect;
  108.     GetDItem(dwind, ok, &itemtype, &itemhandle, &borderRect);
  109.     /* ok is defined as 1 in the interfaces. If you'd like another item outlined, */
  110.     /* change this number, of course. */
  111.     InsetRect(&borderRect, -4, -4);
  112.     PenSize(3, 3);
  113.     FrameRoundRect(&borderRect, 16, 16);
  114.     PenSize(1, 1);
  115. }
  116.  
  117. /* end BorderDefault */
  118.  
  119. /* Replaces constantly calling Get/Draw string */
  120.  
  121. static void DrawIndString(short strList, short index)
  122. {
  123.     Str255 theString;
  124.     GetIndString(theString, strList, index);
  125.     DrawString(theString);
  126.     
  127. }
  128.  
  129. /* end DrawIndString */
  130.  
  131. /* DateBox actually draws the two dates in the userItem rect set up for them */
  132.  
  133. static pascal void DateBox(WindowPtr rDial, short dinum)
  134. {
  135. #pragma unused (dinum )
  136.     short kindI, oldFont;
  137.     Handle HandL;
  138.     Rect itemRect;
  139.     Rect thiRect;
  140.     short  tWide, tHi;
  141.     short tenFnum, oldSize;
  142.     PicHandle theHittedThing;
  143.     short index = 0;
  144.     
  145.     GetDItem(rDial, kManDateItem, &kindI, &HandL, &itemRect);
  146.     EraseRect(&itemRect);
  147.     
  148.     /* I am using Monaco here because it's a monospaced font, and I want */
  149.     /* the date things not to shift all the time by characters changing width */
  150.     
  151.     GetFNum("\pMonaco", &tenFnum);
  152.     
  153.     /* save the old font and size */
  154.     oldFont = rDial->txFont;
  155.     oldSize = rDial->txSize;
  156.     
  157.     /* set the new font and size */
  158.     TextFont(tenFnum);
  159.     TextSize(12);
  160.     
  161.     /* plot our numbers */
  162.     MoveTo(itemRect.left, itemRect.bottom - 7);
  163.     
  164.     /* I'm doing getpens so I can make the correct inversion and hit testing rectangles */
  165.     
  166.     GetPen((Point *)&(dialogDateStruct.charBox[index].top));
  167.     WritePicturedNum(dialogDateStruct.dialogDate.startDate.month, 2);
  168.     GetPen((Point *)&(dialogDateStruct.charBox[index].bottom));
  169.     index++;
  170.     
  171.     DrawChar('/');
  172.     GetPen((Point *)&(dialogDateStruct.charBox[index].top));
  173.     WritePicturedNum(dialogDateStruct.dialogDate.startDate.day, 2);
  174.     GetPen((Point *)&(dialogDateStruct.charBox[index].bottom));
  175.     index++;
  176.     
  177.     DrawChar('/');
  178.     GetPen((Point *)&(dialogDateStruct.charBox[index].top));
  179.     WritePicturedNum(dialogDateStruct.dialogDate.startDate.year, 4);
  180.     GetPen((Point *)&(dialogDateStruct.charBox[index].bottom));
  181.     index++;
  182.     
  183.     DrawIndString(kGeneralStrings, kToWord);
  184.     GetPen((Point *)&(dialogDateStruct.charBox[index].top));
  185.     WritePicturedNum(dialogDateStruct.dialogDate.endDate.month, 2);
  186.     GetPen((Point *)&(dialogDateStruct.charBox[index].bottom));
  187.     index++;
  188.     
  189.     DrawChar('/');
  190.     GetPen((Point *)&(dialogDateStruct.charBox[index].top));
  191.     WritePicturedNum(dialogDateStruct.dialogDate.endDate.day, 2);
  192.     GetPen((Point *)&(dialogDateStruct.charBox[index].bottom));
  193.     index++;
  194.     
  195.     DrawChar('/');
  196.     GetPen((Point *)&(dialogDateStruct.charBox[index].top));
  197.     WritePicturedNum(dialogDateStruct.dialogDate.endDate.year, 4);
  198.     GetPen((Point *)&(dialogDateStruct.charBox[index].bottom));
  199.     
  200.     /* draw the arrow picture thing */
  201.     /* assumes itemRect && index ain't changed, so don't mess 'em up before here */
  202.     /* get my picture of the up/down arrows */
  203.     theHittedThing = GetPicture(129);
  204.     thiRect = (*theHittedThing)->picFrame;
  205.     
  206.     /* get the basic dimensions of the picture */
  207.     tWide = thiRect.right - thiRect.left;
  208.     tHi = thiRect.bottom - thiRect.top;
  209.     
  210.     /* move it to after the last year */
  211.     thiRect.left = dialogDateStruct.charBox[index].right + 5;
  212.     thiRect.right = thiRect.left + tWide;
  213.     thiRect.bottom = itemRect.bottom - 7;
  214.     thiRect.top = thiRect.bottom - tHi;
  215.     
  216.     DrawPicture(theHittedThing, &thiRect);
  217.     /* reset arrowHits */
  218.     dialogDateStruct.arrowHits[0] = thiRect;
  219.     dialogDateStruct.arrowHits[1] = thiRect;
  220.     
  221.     dialogDateStruct.arrowHits[0].bottom = dialogDateStruct.arrowHits[0].top + ((dialogDateStruct.arrowHits[0].bottom -
  222.                                                                                  dialogDateStruct.arrowHits[0].top) / 2);
  223.     dialogDateStruct.arrowHits[1].top = dialogDateStruct.arrowHits[0].bottom + 1;       /* slight slop */
  224.     ReleaseResource((Handle)theHittedThing);
  225.     
  226.     for (index = 0; index < 6; index++) {
  227.         FontInfo theFInfo;
  228.         GetFontInfo(&theFInfo);
  229.         /* set the top and bottom of the character rectangles */
  230.         dialogDateStruct.charBox[index].bottom += 4;
  231.         dialogDateStruct.charBox[index].top = dialogDateStruct.charBox[index].bottom - theFInfo.ascent - theFInfo.descent -
  232.             theFInfo.leading;
  233.         
  234.         /* invert the current one so the user knows it's active */
  235.         if (dialogDateStruct.editHot && dialogDateStruct.whichHitting == index)
  236.             InvertRect(&dialogDateStruct.charBox[index]);
  237.     }
  238.     /* reset to the old font and size */
  239.     TextFont(oldFont);
  240.     TextSize(oldSize);
  241.     
  242. }
  243.  
  244. /* end DateBox */
  245.  
  246. /* adjusts the current date if a key has been hit, mouse clicked, whatever */
  247. /* adding some extra stuff for using this from keystrokes */
  248. static void AdjustDate(short incOr, DialogPtr rDial, short newVal)
  249. {
  250.     short *theThing;
  251.     DateStruct originalDate;
  252.     RgnHandle oldClip, currentClip;
  253.     short amt;
  254.     
  255.     /* save the initial months for rollover checking */
  256.     originalDate = dialogDateStruct.dialogDate;
  257.     
  258.     /* switch off which unit we're currently tracking */
  259.     switch (dialogDateStruct.whichHitting) {
  260.         case kStartMonth:
  261.             theThing = (short *)&dialogDateStruct.dialogDate.startDate.month;
  262.             break;
  263.         case kStartDay:
  264.             theThing = (short *)&dialogDateStruct.dialogDate.startDate.day;
  265.             break;
  266.         case kStartYear:
  267.             theThing = (short *)&dialogDateStruct.dialogDate.startDate.year;
  268.             
  269.             break;
  270.         case kEndMonth:
  271.             theThing = (short *)&dialogDateStruct.dialogDate.endDate.month;
  272.             
  273.             break;
  274.         case kEndDay:
  275.             theThing = (short *)&dialogDateStruct.dialogDate.endDate.day;
  276.             break;
  277.         case kEndYear:
  278.             theThing = (short *)&dialogDateStruct.dialogDate.endDate.year;
  279.             break;
  280.     }
  281.     /* dammit! oh, nevermind, I figured it out */
  282.     if (newVal < 0) {
  283.         /* set the increment to plus one or minus 1 */
  284.         amt = (incOr ? -1 : 1);
  285.         /* and change the value */
  286.         *theThing += amt;
  287.     } else {
  288.         if (dialogDateStruct.whichHitting == kStartYear || dialogDateStruct.whichHitting == kEndYear) {
  289.             /* I forget why this is here, but I must have had a good reason */
  290.         } else {
  291.             short oldThing;
  292.             /* ok, dammit, if it's a two-stroker then do 2 stroke things */
  293.             /* Which means the user might have hit two numbers quickly (like 1 0 to indicate 10) */
  294.             /* so we have to handle that, instead of treating every numeric stroke as a */
  295.             /* number in the 1's column */
  296.             if (TickCount() < dialogDateStruct.lastLetterTick) {
  297.                 oldThing = *theThing;
  298.                 *theThing *= 10;
  299.                 /* check range for months, forget days */
  300.                 if (dialogDateStruct.whichHitting == kStartMonth || dialogDateStruct.whichHitting == kEndMonth) {
  301.                     
  302.                     if ((*theThing + newVal) < 13) {
  303.                         /* if over 13, then reset it */
  304.                         newVal = *theThing + newVal;
  305.                     }
  306.                 } else {
  307.                     /* Should we do days? OK, but forget february */
  308.                     if ((*theThing + newVal) < 32) {
  309.                         newVal = *theThing + newVal;
  310.                     }
  311.                 }
  312.             }
  313.             *theThing = newVal;
  314.             
  315.             /* set up for the second in a two-key number entry. They have to hit the second */
  316.             /* key within 60 ticks for it to count with the first one */
  317.             dialogDateStruct.lastLetterTick = TickCount() + 60;
  318.         }
  319.     }
  320.     /* let the utils figure out if they wrapped or not */
  321.     
  322.     Date2Secs(&dialogDateStruct.dialogDate.startDate, &dialogDateStruct.dialogDate.startDateraw);
  323.     Date2Secs(&dialogDateStruct.dialogDate.endDate, &dialogDateStruct.dialogDate.endDateraw);
  324.     /* HAHAHA and now the other way */
  325.     Secs2Date(dialogDateStruct.dialogDate.startDateraw, &dialogDateStruct.dialogDate.startDate);
  326.     Secs2Date(dialogDateStruct.dialogDate.endDateraw, &dialogDateStruct.dialogDate.endDate);
  327.     
  328.     /* check for rollovers */
  329.     /* I _think_ the only rollover occurs with days, so check that only */
  330.     /* Nope, have to check for months rolling over years and days */
  331.     /* Stop being inefficient, and just keep building a bigger region, OK? */
  332.     
  333.     /* Save the old clipping region, and set up a new one that */
  334.     /* will include just the rectangles that change */
  335.     oldClip = NewRgn();
  336.     GetClip(oldClip);
  337.     currentClip = NewRgn();
  338.     OpenRgn();
  339.     
  340.     /* clip to the currently hitting character */
  341.     FrameRect(&dialogDateStruct.charBox[dialogDateStruct.whichHitting]);
  342.     
  343.     /* now go through any side-effects and clip to them also */
  344.     /* Side effects like days rolling past 31 and the month changing */
  345.     
  346.     switch (dialogDateStruct.whichHitting) {
  347.         case kStartMonth:
  348.             /* Did the year or day change because of this month change? */
  349.             if (originalDate.startDate.year != dialogDateStruct.dialogDate.startDate.year)
  350.                 FrameRect(&dialogDateStruct.charBox[kStartYear]);
  351.             if (originalDate.startDate.day != dialogDateStruct.dialogDate.startDate.day)
  352.                 FrameRect(&dialogDateStruct.charBox[kStartDay]);
  353.             
  354.             break;
  355.         case kStartDay:
  356.             /* Did the month change because of this day change? */
  357.             
  358.             if (originalDate.startDate.month != dialogDateStruct.dialogDate.startDate.month)
  359.                 FrameRect(&dialogDateStruct.charBox[kStartMonth]);
  360.             
  361.             break;
  362.             
  363.         case kEndMonth:
  364.             /* Did the year or day change because of this month change? */
  365.             if (originalDate.endDate.year != dialogDateStruct.dialogDate.endDate.year)
  366.                 FrameRect(&dialogDateStruct.charBox[kEndYear]);
  367.             if (originalDate.endDate.day != dialogDateStruct.dialogDate.endDate.day)
  368.                 FrameRect(&dialogDateStruct.charBox[kEndDay]);
  369.             
  370.             
  371.             break;
  372.         case kEndDay:
  373.             /* Did the month change because of this day change? */
  374.             
  375.             if (originalDate.endDate.month != dialogDateStruct.dialogDate.endDate.month)
  376.                 FrameRect(&dialogDateStruct.charBox[kEndMonth]);
  377.             
  378.             break;
  379.             
  380.     }
  381.     CloseRgn(currentClip);
  382.     
  383.     /* Clip to these boxes */
  384.     SetClip(currentClip);
  385.     
  386.     /* redraw the date */
  387.     DateBox(rDial, kManDateItem);
  388.     
  389.     /* restore original clip */
  390.     SetClip(oldClip);
  391.     
  392.     /* dispose of our temp regions */
  393.     DisposeRgn(currentClip);
  394.     DisposeRgn(oldClip);
  395. }
  396.  
  397. /* end AdjustDate */
  398.  
  399. /* DateThingerFilter */
  400. /* Filters events for the date dialog */
  401.  
  402. static pascal Boolean DateThingerFilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
  403. {
  404. #pragma unused (itemHit )
  405.     static enum  {
  406.         kGoingUp = 1, kGoingDown
  407.     };
  408.     Boolean retVal = false;
  409.     WindowPtr theOld;
  410.     unsigned long qq;
  411.     short kindI;
  412.     short upOrDown = 0;
  413.     Handle HandL;
  414.     Rect itemRect;
  415.     long tempLong;
  416.     Point thePoint;
  417.     GetPort(&theOld);
  418.     SetPort(theDialog);
  419.     if (theEvent->what == mouseDown) {
  420.         
  421.         /* if the event is a mouse down, it could be in a number or an arrow */
  422.         GetMouse(&thePoint);
  423.         
  424.         /* check arrow box first */
  425.         if (PtInRect(thePoint, &dialogDateStruct.arrowHits[0])) {
  426.             upOrDown = kGoingUp;
  427.         } else {
  428.             if (PtInRect(thePoint, &dialogDateStruct.arrowHits[1])) {
  429.                 upOrDown = kGoingDown;
  430.             }
  431.         }
  432.         /* if upOrDown was set, then it was in a arrow */
  433.         if (upOrDown) {
  434.             /* for the arrow picture */
  435.             
  436.             InvertRect(&dialogDateStruct.arrowHits[upOrDown - 1]);
  437.             /* stay with it and blink */
  438.             Delay(8, &tempLong);
  439.             
  440.             while (StillDown()) {
  441.                 /* if they are holding down in the arrow thing, then wait 8 ticks */
  442.                 /* for them to come up, if they don't adjust again */
  443.                 /* making this a subroutine to keep the clutter out of this filter */
  444.                 AdjustDate(upOrDown - 1, theDialog, -1);
  445.                 Delay(8, &tempLong);
  446.             }
  447.             InvertRect(&dialogDateStruct.arrowHits[upOrDown - 1]);
  448.             
  449.         } else {
  450.             /* they didn't click in an arrow, maybe they clicked in a number */
  451.             for (qq = 0; qq < 6; qq++) {
  452.                 /* see if in the hot numbers */
  453.                 if (PtInRect(thePoint, &dialogDateStruct.charBox[qq])) {
  454.                     dialogDateStruct.editHot = true;
  455.                     dialogDateStruct.whichHitting = qq;
  456.                     
  457.                     /* invalidate the whole date so the new number */
  458.                     /* gets inverted and the old one loses it's invert */
  459.                     GetDItem(theDialog, kManDateItem, &kindI, &HandL, &itemRect);
  460.                     InvalRect(&itemRect);
  461.                     retVal = true;
  462.                     break;
  463.                 }
  464.             }
  465.         }
  466.     } else {
  467.         
  468.         /* see if they entered a number or arrow or tab */
  469.         if (theEvent->what == keyDown) {
  470.             char theKey = theEvent->message &charCodeMask;
  471.             
  472.             if (theKey == kTabKey && dialogDateStruct.editHot) {
  473.                 /* OK dang it, I'll add shift-reverse tabbing. grumble grumble */
  474.                 
  475.                 /* blow away the lastKey ticks */
  476.                 
  477.                 dialogDateStruct.lastLetterTick = 0;
  478.                 InvalRect(&dialogDateStruct.charBox[dialogDateStruct.whichHitting]);
  479.                 
  480.                 if (theEvent->modifiers & shiftKey)
  481.                     dialogDateStruct.whichHitting--;
  482.                 else
  483.                     dialogDateStruct.whichHitting++;
  484.                 
  485.                 /* wrap around on tabbing */
  486.                 if (dialogDateStruct.whichHitting >= 6)
  487.                     dialogDateStruct.whichHitting = kStartMonth;
  488.                 
  489.                 if (dialogDateStruct.whichHitting < 0)
  490.                     dialogDateStruct.whichHitting = kEndYear;
  491.                 
  492.                 InvalRect(&dialogDateStruct.charBox[dialogDateStruct.whichHitting]);
  493.                 
  494.             } else {
  495.                 /* see if it's a number, or heck, an arrow */
  496.                 if ((theKey > 0x2f && theKey < 0x3a) && dialogDateStruct.editHot) {
  497.                     /* hmmmm. Now what do we do? */
  498.                     /* I'm just going to stuff the number in the last digit of the year, or */
  499.                     /* the month/day */
  500.                     /* forget it, let the real thing figure it out */
  501.                     AdjustDate(nil, theDialog, theKey - 0x30);
  502.                     
  503.                 } else {
  504.                     /* do some other standard key stuff */
  505.                     switch (theKey) {
  506.                         short tempItem;
  507.                         Handle tempHandle;
  508.                         Rect tempRect;
  509.                         
  510.                         case kLeftArrowKey:
  511.                         case kDownArrowKey:
  512.                             upOrDown = kGoingDown;
  513.                             break;
  514.                         case kRightArrowKey:
  515.                         case kUpArrowKey:
  516.                             upOrDown = kGoingUp;
  517.                             break;
  518.                         case kEscKey:
  519.                             *itemHit = 2;
  520.                             GetDItem(theDialog, 1, &tempItem, &tempHandle, &tempRect);
  521.                             
  522.                             if (tempItem == ctrlItem) {
  523.                                 /* much more likely that this may not be a button */
  524.                                 
  525.                                 HiliteControl(SnatchHandle(theDialog, cancel), inButton);
  526.                                 Delay(8, &tempLong);        /* wait about 8 ticks so they can see it */
  527.                                 HiliteControl(SnatchHandle(theDialog, cancel), false);
  528.                                 retVal = true;
  529.                             }
  530.                             break;
  531.                         case kReturnKey:
  532.                         case kEnterKey:                     /* enter key */
  533.                             /* This filters for Return or Enter as item 1, and Esc as item 2 */
  534.                             *itemHit = 1;                   /* change whatever the current item is to the OK item */
  535.                             /* now we need to invert the button */
  536.                             GetDItem(theDialog, 1, &tempItem, &tempHandle, &tempRect);
  537.                             if (tempItem == ctrlItem) {
  538.                                 /* double check for the unlikely event that this is _not_ a button */
  539.                                 HiliteControl(SnatchHandle(theDialog, ok), inButton);
  540.                                 Delay(8, &tempLong);        /* wait about 8 ticks so they can see it */
  541.                                 HiliteControl(SnatchHandle(theDialog, ok), false);
  542.                                 
  543.                                 retVal = true;
  544.                             }
  545.                             break;
  546.                             
  547.                         default:
  548.                             /* nothing */
  549.                             break;
  550.                     }
  551.                 }
  552.             }
  553.         }
  554.     }
  555.     
  556.     /* did anything actually happen? */
  557.     if (upOrDown)
  558.         AdjustDate(upOrDown - 1, theDialog, -1);
  559.     
  560.     SetPort(theOld);
  561.     return(retVal);
  562. }
  563.  
  564. /* end DateThingerFilter */
  565.  
  566. /* DateSetterDialog */
  567. /* actually displays and runs the dialog */
  568. void DateSetterDialog(void)
  569. {
  570.     DialogPtr tdial = GetNewDialog(kDateDialog, nil, (WindowPtr)-1);
  571.     short hitItem;
  572.     Boolean noExit = true;
  573.     short kindI;
  574.     Handle HandL;
  575.     Rect itemRect;
  576.     
  577.     /* set up our date thing user item */
  578.     GetDItem(tdial, kManDateItem, &kindI, &HandL, &itemRect);
  579.     SetDItem(tdial, kManDateItem, userItem, (Handle)DateBox, &itemRect);
  580.     
  581.     /* default some values */
  582.     dialogDateStruct.editHot = true;
  583.     dialogDateStruct.whichHitting = 0;
  584.     GetDateTime(&dialogDateStruct.dialogDate.startDateraw);
  585.     GetDateTime(&dialogDateStruct.dialogDate.endDateraw);
  586.     Secs2Date(dialogDateStruct.dialogDate.startDateraw, &dialogDateStruct.dialogDate.startDate);
  587.     Secs2Date(dialogDateStruct.dialogDate.endDateraw, &dialogDateStruct.dialogDate.endDate);
  588.     
  589.     /* set up for bordering OK */
  590.     GetDItem(tdial, kBorderBox, &kindI, &HandL, &itemRect);
  591.     SetDItem(tdial, kBorderBox, kindI, (Handle)BorderDefault, &itemRect);
  592.     
  593.     /* dialog was created hidden, so show it */
  594.     ShowWindow(tdial);
  595.     DrawDialog(tdial);
  596.     
  597.     do {
  598.         ModalDialog((ModalFilterProcPtr)DateThingerFilter, &hitItem);
  599.         switch (hitItem) {
  600.             case ok:
  601.             case cancel:
  602.                 noExit = false;
  603.                 break;
  604.         }
  605.     }
  606.             while (noExit);
  607.     if (hitItem == ok) {
  608.         
  609.     }
  610.     DisposDialog(tdial);
  611.     
  612. }
  613.  
  614. /* end DateSetterDialog */
  615.